package com.zzq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzq.domain.entity.SmileBlindboxPrizeRecord;
import com.zzq.domain.entity.SmileClient;
import com.zzq.mapper.SmileBlindboxPrizeRecordMapper;
import com.zzq.service.SmileBlindboxPrizeRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzq.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 小布
 * @since 2023-11-07
 */
@Service
public class SmileBlindboxPrizeRecordServiceImpl extends ServiceImpl<SmileBlindboxPrizeRecordMapper, SmileBlindboxPrizeRecord> implements SmileBlindboxPrizeRecordService {

    @Autowired
    SmileBlindboxPrizeRecordMapper blindboxPrizeRecordMapper;
    @Override
    public SmileBlindboxPrizeRecord getLastRecord(Long clientId) {
        LambdaQueryWrapper<SmileBlindboxPrizeRecord> queryWrapper=new LambdaQueryWrapper();
        queryWrapper.eq(SmileBlindboxPrizeRecord::getClientId,clientId);
        queryWrapper.orderByDesc(SmileBlindboxPrizeRecord::getCreatedTime);
        List<SmileBlindboxPrizeRecord> blindboxPrizeRecordList = blindboxPrizeRecordMapper.selectList(queryWrapper);
        if (ObjectUtils.isEmpty(blindboxPrizeRecordList)) {
            return null;
        }else {
            return blindboxPrizeRecordList.stream().findFirst().get();
        }

    }
}
